#!user/bin/env python3
# -- coding: utf-8 --
# @Createtime：2023/8/28 14:12
# @Updatetime：14:12
# @Author：Test008
# @File：3-CSS案例
# @Description：古诗文网站登录并收藏取消收藏操作


import time

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.implicitly_wait(5)
driver.get('https://www.gushiwen.cn/')
# 点击我的按钮
my_button = driver.find_element(By.CSS_SELECTOR, '.son1 a:nth-last-child(2)').click()
# 输入账号密码
email = driver.find_element(By.CSS_SELECTOR, '#email').send_keys('1478243841@qq.com')
pwd = driver.find_element(By.CSS_SELECTOR, '#pwd').send_keys('123456')
# 停留10秒，前端输入验证码，再点击登录
time.sleep(10)
denglu = driver.find_element(By.CSS_SELECTOR, '#denglu').click()
# 点击名句
mingju = driver.find_element(By.CSS_SELECTOR, '.son1 a:nth-child(2)').click()
# 选择诗文中第一首诗，点击收藏,再取消
# 需要向下滑动到收藏元素可见
ele = driver.find_element(By.CSS_SELECTOR, '#likeImg71871')
driver.execute_script("arguments[0].scrollIntoView(false);",ele)
shoucang = driver.find_element(By.CSS_SELECTOR, '#likeImg71871').click()
quxiaoshoucang = driver.find_element(By.CSS_SELECTOR, '#likeImg71871').click()

# 回到我的
driver.find_element(By.CSS_SELECTOR, '.son1 a:nth-last-child(2)').click()
# 再回到古诗文首页
home_page = driver.find_element(By.CSS_SELECTOR, '.cont .left a:first-child').click()

time.sleep(3)

driver.quit()
